﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.Security;
using System.Web.SessionState;
using System.Web.Http;
using System.Web.Optimization;
using log4net.Config;
using Newtonsoft.Json.Serialization;

namespace WeChat.Web
{
    public class Global : HttpApplication
    {
        void Application_Start(object sender, EventArgs e)
        {
            // 在应用程序启动时运行的代码
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            //初始化Log4Net
            XmlConfigurator.Configure();

            //初始化Autofac（注入业务、仓储、工具类实例）
            AutoFacBootStrapper.AutoFacInit();

            //初始化AutoMapper（注册Dto与Domain映射关系）
            AutoMapperBootStrapper.RegisterMaps();

            //设置JSON序列化方式-驼峰命名
            HttpConfiguration config = GlobalConfiguration.Configuration;
            config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            config.Formatters.JsonFormatter.UseDataContractJsonSerializer = false;
        }
    }
}